package com.conwax.gmap;

import java.io.Serializable;

import org.apache.wicket.Session;
import org.apache.wicket.behavior.AbstractBehavior;

import com.conwax.gmap.event.GEventHandler;
import com.conwax.gmap.event.GEventSource;

public class Map2 extends GMapJSElement implements GEventSource, Serializable {

	private static final long serialVersionUID = 1L;
	private int id;
	private GLatLng center;
	private int zoom;
	private DivElementContainer divElement;

	public Map2(final DivElementContainer divElement) {
		this.id = Session.get().nextSequenceValue();
		this.divElement = divElement;
		divElement.setOutputMarkupId(true);
		divElement.add(new Map2Behavior());
	}

	public void setCenter(GLatLng latLng, int i) {
		this.center = latLng;
		this.zoom = i;
	}

	public int getId() {
		return id;
	}
	
	@Override
	public String getJSInit() {
		String jsInit = "WicketConGoogle.Map2(\""
		+ id + "\", \"" + divElement.getMarkupId() + "\");"
		+ "WicketConGoogle.maps[" + id + "].map.setCenter("
		+ center.getJSInit() + ", " + zoom
		+ ");";
		return jsInit;
	}

	public void addListener(GEventHandler listener) {

	}
	
	public class Map2Behavior extends AbstractBehavior
	{

		private static final long serialVersionUID = 1L;

		public Map2 getMap2()
		{
			return Map2.this;
		}
	}

}
